module.exports = function(app) {
    app.all('/*', function(req, res, next) {
        var ip = req.headers['x-real-ip'] || req.socket.remoteAddress;
        console.log([
            ip + ' -',
            '[' + new Date().toUTCString() + ']',
            '\"' + req.method + ' ' + req.url,
            'HTTP/' + req.httpVersionMajor + '.' + req.httpVersionMinor + '\" ' + res.statusCode,
            req.headers['user-agent'],
            req.method === 'POST' ? JSON.stringify(req.body) : ''
        ].join(' - '));

        if (req.method === 'POST') {
            var data = null;
            try {
                data = JSON.parse(req.body.data);
            } catch (e) {
                next(e);
                return;
            }
            req.data = data;
        }
        next();
    });

    app.get('/', function(req, res, next) {
        res.send('一切都是短暂的，只有掌控世间万物的数学公式和物理定律才是永恒的。');
    });
};
